/* 
 * --------------------------------------------------------------
 * This is the android input class that implements the basic game
 * input interface.
 * 2011, by Wu Mu Xian
 * --------------------------------------------------------------
*/

package mygame.myandroidgameframework;

import java.util.List;

import android.content.Context; 
import android.os.Build.VERSION; 
import android.view.View;

import mygame.basicgameframework.Input;

public class MyAndroidInput implements Input {
	
	MyAndroidAccelerometerHandler accelHandler; // the accelerometer handler 
	MyAndroidKeyboardHandler keyHandler; // the key handler
	MyAndroidTouchHandler touchHandler; // the touch handler
	
	// constructor
	public MyAndroidInput(Context context, View view, float scaleX, float scaleY) { 
        accelHandler = new MyAndroidAccelerometerHandler(context); 
        keyHandler = new MyAndroidKeyboardHandler(view);                
        if(Integer.parseInt (VERSION.SDK ) < 5)  
            touchHandler = new MyAndroidSingleTouchHandler(view, scaleX, scaleY); 
        else 
            touchHandler = new MyAndroidMultiTouchHandler(view, scaleX, scaleY);         
    }

	// check if a key is pressed
	public boolean isKeyPressed(int keyCode) {
		return keyHandler.isKeyPressed(keyCode);
	}
	
	// check if the screen is touched
	public boolean isTouchDown(int pointer) {
		return touchHandler.isTouchDown(pointer);
	}

	// get the x-coordinate of touch point
	public int getTouchX(int pointer) {
		return touchHandler.getTouchX(pointer);
	}

	// get the y-coordinate of touch point
	public int getTouchY(int pointer) {
		return touchHandler.getTouchY(pointer);
	}

	// get the acceleration of x-axis
	public float getAccelX() {
		return accelHandler.getAccelX();
	}

	// get the acceleration of y-axis
	public float getAccelY() {
		return accelHandler.getAccelY();
	}

	// get the acceleration of z-axis
	public float getAccelZ() {
		return accelHandler.getAccelZ();
	}

	// get the touch events
	public List<TouchEvent> getTouchEvents() {
		return touchHandler.getTouchEvents();
	}

	// get the key events
	public List<KeyEvent> getKeyEvents() {
		return keyHandler.getKeyEvents();
	}
}
